package com.gexiaobao.pigeon.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.view.isVisible
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.model.bean.PassProjectInfo
import com.gexiaobao.pigeon.app.model.bean.PassProjectInfoBean

/**
 * @Author      : hxw
 * @Date        : 2024/7/22 11:36
 * @Describe    :
 */
class RxDialogDetailInfo(context: Context?) : RxDialog(context!!) {

    private lateinit var sureView: AppCompatTextView
    private lateinit var tvDialogName: AppCompatTextView
    private lateinit var tvDialogLocation: AppCompatTextView
    private lateinit var tvDialogRingId: AppCompatTextView
    private lateinit var tvDialogHomeTime: AppCompatTextView
    private lateinit var tvDialogSpeed: AppCompatTextView
    private lateinit var tvDialogRank: AppCompatTextView
    private lateinit var tvDialogPassRank: AppCompatTextView
    private lateinit var tvDialogRewards: AppCompatTextView
    private lateinit var llDialogPassRank: LinearLayout

    init {
        initView()
    }

    @SuppressLint("MissingInflatedId")
    private fun initView() {
        val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_single_pass_project, null)
        sureView = dialogView.findViewById(R.id.tvDialogSure)
        tvDialogName = dialogView.findViewById(R.id.tvDialogName)
        tvDialogLocation = dialogView.findViewById(R.id.tvDialogLocation)
        tvDialogRingId = dialogView.findViewById(R.id.tvDialogRingId)
        tvDialogHomeTime = dialogView.findViewById(R.id.tvDialogHomeTime)
        tvDialogSpeed = dialogView.findViewById(R.id.tvDialogSpeed)
        tvDialogRank = dialogView.findViewById(R.id.tvDialogRank)
        tvDialogRewards = dialogView.findViewById(R.id.tvDialogRewards)
        tvDialogPassRank = dialogView.findViewById(R.id.tvDialogPassRank)
        llDialogPassRank = dialogView.findViewById(R.id.llDialogPassRank)

        setContentView(dialogView)
    }

    fun setSureListener(listener: View.OnClickListener?) {
        sureView.setOnClickListener(listener)
    }

    fun setDta(it: PassProjectInfoBean) {
        tvDialogName.text = it.entryName.ifEmpty { "--" }
        tvDialogLocation.text = it.location.ifEmpty { "--" }
        tvDialogRingId.text = it.ringId.ifEmpty { "--" }
        tvDialogHomeTime.text = it.homingTime.ifEmpty { "--" }
        tvDialogSpeed.text = it.speed.ifEmpty { "--" }
        tvDialogRank.text = it.projectRank.toString()
        tvDialogRewards.text = it.money.ifEmpty { "--" }
        tvDialogPassRank.text = it.rank.toString()
        llDialogPassRank.isVisible = true
    }

    fun setDataAppPass(it: PassProjectInfo) {
        tvDialogName.text = it.entryName.ifEmpty { "--" }
        tvDialogLocation.text = it.location.ifEmpty { "--" }
        tvDialogRingId.text = it.ringId.ifEmpty { "--" }
        tvDialogHomeTime.text = it.homingTime.ifEmpty { "--" }
        tvDialogSpeed.text = it.speed.ifEmpty { "--" }
        tvDialogRank.text = it.projectRank.toString()
        tvDialogRewards.text = it.money.ifEmpty { "--" }
        tvDialogPassRank.text = it.rank.toString()
        llDialogPassRank.isVisible = false
    }
}